﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Small.Html.Options;

namespace Small.Html.UI
{
   public static class HtmlJqGrid
    {
       /// <summary>
       /// JqGrid扩展
       /// </summary>
       /// <param name="helper"></param>
       /// <param name="id"></param>
       /// <param name="options"></param>
       /// <returns></returns>
       public static MvcHtmlString JqGrid(this HtmlHelper helper, string id, JqGridOptions  options) 
       {

           return new MvcHtmlString( GenerateJsString(id, options));
       }

       /// <summary>
       /// 生成Js
       /// </summary>
       /// <param name="id"></param>
       /// <param name="options"></param>
       /// <returns></returns>
       private static string GenerateJsString(string id, JqGridOptions options) 
       {
           StringBuilder builder = new StringBuilder();
           builder.Append("$('#" + id + "').jqGrid({" + options.GenerateString() + "})");
           return builder.ToString();

       }
    }
}
